layui.config({
	base : "/dhjdglxt/modules/util/"//自定义加载的模块
}).use(['form','layer','jquery','layedit','laydate','laypage','table','commUtil','element'],function(){
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		layedit = layui.layedit,
		laydate = layui.laydate,
		$ = layui.jquery;
		var table = layui.table;
		var commUtil = layui.commUtil;
		var element = layui.element;
		
		laydate.render({
		    elem: '#startTime',
		    trigger: 'click',
		    type:'date'
		});
		
		laydate.render({
		    elem: '#endTime',
		    trigger: 'click',
		    type:'date'
		});
		laydate.render({
		    elem: '#proctionDate',
		    trigger: 'click',
		    type:'date'
		});
		laydate.render({
		    elem: '#useDate',
		    trigger: 'click',
		    type:'date'
		});
		laydate.render({
		    elem: '#jrygrq',
		    trigger: 'click',
		    type:'date'
		});
		laydate.render({
		    elem: '#tcygrq',
		    trigger: 'click',
		    type:'date'
		});
		laydate.render({
		    elem: '#offDate',
		    trigger: 'click',
		    type:'date'
		});
		laydate.render({
		    elem: '#gjDate',
		    trigger: 'click',
		    type:'date'
		});
		laydate.render({
		    elem: '#qfDate',
		    trigger: 'click',
		    type:'date'
		});
		laydate.render({
		    elem: '#dtyxDate',
		    trigger: 'click',
		    type:'date'
		});
		laydate.render({
		    elem: '#dtbfDate',
		    trigger: 'click',
		    type:'date'
		});
		
		//计划选择
		$.get(basePath + '/service/airplanebaseinfo/airplanebaseinfo/ztree', function (data) {
	        if(data){
	            var optionStr="";
	            for(var i=0;i<data.length;i++){
	                var select="";
	                if($('#gljhid').val()==data[i].id){
	                    select=" selected='selected' "
	                }
	                optionStr+="<option "+select+" value='"+data[i].id+"'>"+data[i].name+"</option>";
	            }
	            $("#gljh").append(optionStr);
	            form.render('select');
	        }
	    });
		//监听提交
		form.on('submit(formSubmit)', function(data){
			var users = $("#nextUser").val();
	        var parms = "";
	        var title = ""
	        parms = "type=users&value=nextUser&name=nextUserName&chkType=radio";
	        title = "流程人员选择选择";
	        openGneDiv("380px", "400px", basePath + "/service/ztree/ztreeInfo?" + parms, title);
	        return false;
		});
		
		$("#nextUserName").click(function(){
			 var users = $("#nextUser").val();
		        var parms = "";
		        var title = ""
		        parms = "type=users&value=nextUser&name=nextUserName&chkType=radio";
		        title = "流程人员选择选择";
		        openGneDiv("380px", "400px", basePath + "/service/ztree/ztreeInfo?" + parms, title);
		        return false;
			
		});
		$("#closeWin").click(function(){
			 
			layer.closeAll();
		});
		
		//监听保存
		form.on('submit(saveSubmit)', function(data){
			var recId='0';
			data.field.status = 0;
			if(data.field.recId!=''){
				recId=data.field.recId;
			}
			$.ajax({
		        type: "PUT",
		        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/'+recId,
		        data: data.field,
		        async:false,
		        dataType: "json",
		        success: function(data){
		        	if(data.code=='0'){
		        		layer.msg("操作成功", {icon: 1});
		        		 parent.location.reload();	
		    		} else {
		    			layer.msg("操作失败", {icon: 0});
		    		}
		        }
		    });
		});
		//监听保存
		form.on('submit(saveUphold)', function(data){
			var recId='0';
			if(data.field.recId!=''){
				recId=data.field.recId;
			}
			$.ajax({
		        type: "PUT",
		        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/uphold/'+recId,
		        data: data.field,
		        async:false,
		        dataType: "json",
		        success: function(data){
		        	if(data.code=='0'){
		        		layer.msg("操作成功", {icon: 1});
		        		 parent.location.reload();	
		    		} else {
		    			layer.msg("操作失败", {icon: 0});
		    		}
		        }
		    });
		});
		//监听保存
		form.on('submit(save)', function(data){
			var recId='0';
			if(data.field.recId!=''){
				recId=data.field.recId;
			}
			$.ajax({
		        type: "PUT",
		        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/'+recId,
		        data: data.field,
		        async:false,
		        dataType: "json",
		        success: function(data){
		        	if(data.code=='0'){
		        		layer.msg("操作成功", {icon: 1});
		        		 parent.location.reload();	
		    		} else {
		    			layer.msg("操作失败", {icon: 0});
		    		}
		        }
		    });
		});
		//三证有效性维护办理保存
		form.on('submit(saveszbg)', function(data){
			parent.$("#transContents").val(data.field.transContents);
			var recId='0';
			if(data.field.recId!=''){
				recId=data.field.recId;
			}
			$.ajax({
		        type: "PUT",
		        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/oacwsave',
		        data: data.field,
		        async:false,
		        dataType: "json",
		        success: function(data){
		        	if(data.code=='0'){
		        		layer.msg("操作成功", {icon: 1});
		        		try{
		        		 var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		        		 if(index==null||typeof(index)=='undefined'){
		        			 var iframeId=parent.document.getElementsByTagName("iframe")[1].id;
		        			 index=iframeId.substring(iframeId.length-1);
		        		 }
		                  parent.layer.close(index); //再执行关闭
		                  parent.document.getElementsByTagName("iframe")[0].contentWindow.location.reload(true);
		        		}catch(e){
		        		}
		    		} else {
		    			layer.msg("操作失败", {icon: 0});
		    		}
		        }
		    });
    		
    		
    	});   
		
		
		//监听保存
		form.on('submit(saveghbg)', function(data){
			
			 var users = $("#nextUser").val();
		        var parms = "";
		        var title = ""
		        parms = "type=users&value=nextUser&name=nextUserName&chkType=radio";
		        title = "流程人员选择选择";
		        openGneDiv("380px", "400px", basePath + "/service/ztree/ztreeInfo?" + parms, title);
		        return false;
			
		});
		//监听保存
		form.on('submit(savecwbg)', function(data){
			
			 var users = $("#nextUser").val();
		        var parms = "";
		        var title = ""
		        parms = "type=users&value=nextUser&name=nextUserName&chkType=radio";
		        title = "流程人员选择选择";
		        openGneDiv("380px", "400px", basePath + "/service/ztree/ztreeInfo?" + parms, title);
		        return false;
		        
		});
		//监听保存
		form.on('submit(flowSubmit)', function(data){
			parent.$("#transContents").val(data.field.transContents);
				var recId='0';
				if(data.field.recId!=''){
					recId=data.field.recId;
				}
				$.ajax({
			        type: "PUT",
			        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/saveHt/'+recId,
			        data: data.field,
			        async:false,
			        dataType: "json",
			        success: function(data){
			        	if(data.code=='0'){
			        		layer.msg("操作成功", {icon: 1});
			        		try{
			        		 var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
			        		 if(index==null||typeof(index)=='undefined'){
			        			 var iframeId=parent.document.getElementsByTagName("iframe")[1].id;
			        			 index=iframeId.substring(iframeId.length-1);
			        		 }
			                  parent.layer.close(index); //再执行关闭
			                  parent.document.getElementsByTagName("iframe")[0].contentWindow.location.reload(true);
			        		}catch(e){
			        		}
			    		} else {
			    			layer.msg("操作失败", {icon: 0});
			    		}
			        }
			    });
			
		});
		//监听保存
		form.on('submit(flowpwSubmit)', function(data){
			parent.$("#transContents").val(data.field.transContents);
				var recId='0';
				if(data.field.recId!=''){
					recId=data.field.recId;
				}
				$.ajax({
			        type: "PUT",
			        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/savePw/'+recId,
			        data: data.field,
			        async:false,
			        dataType: "json",
			        success: function(data){
			        	if(data.code=='0'){
			        		layer.msg("操作成功", {icon: 1});
			        		try{
			        		 var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
			        		 if(index==null||typeof(index)=='undefined'){
			        			 var iframeId=parent.document.getElementsByTagName("iframe")[1].id;
			        			 index=iframeId.substring(iframeId.length-1);
			        		 }
			                  parent.layer.close(index); //再执行关闭
			                  parent.document.getElementsByTagName("iframe")[0].contentWindow.location.reload(true);
			        		}catch(e){
			        		}
			    		} else {
			    			layer.msg("操作失败", {icon: 0});
			    		}
			        }
			    });
		
		});
		//监听保存
		form.on('submit(saveAir)', function(data){
			parent.$("#transContents").val(data.field.transContents);
			var recId='0';
			if(data.field.recId!=''){
				recId=data.field.recId;
			}
			$.ajax({
		        type: "PUT",
		        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/saveAir/'+recId,
		        data: data.field,
		        async:false,
		        dataType: "json",
		        success: function(data){
		        	if(data.code=='0'){
		        		layer.msg("操作成功", {icon: 1});
		        		try{
		        		 var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		        		 if(index==null||typeof(index)=='undefined'){
		        			 var iframeId=parent.document.getElementsByTagName("iframe")[1].id;
		        			 index=iframeId.substring(iframeId.length-1);
		        		 }
		                  parent.layer.close(index); //再执行关闭
		                  parent.document.getElementsByTagName("iframe")[0].contentWindow.location.reload(true);
		        		}catch(e){
		        		}
		    		} else {
		    			layer.msg("操作失败", {icon: 0});
		    		}
		        }
		    });
		});
		//监听保存
		form.on('submit(saveOaInfo)', function(data){
			//var lastIframeId=parent.document.getElementsByTagName("iframe")[0].id;
			//parent.$("#"+lastIframeId).contents()[0].getElementById("transContent").value=data.field.transContents;
			parent.$("#transContents").val(data.field.transContents);
			var recId='0';
			if(data.field.recId!=''){
				recId=data.field.recId;
			}
			$.ajax({
		        type: "PUT",
		        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/oacwsave',
		        data: data.field,
		        async:false,
		        dataType: "json",
		        success: function(data){
		        	if(data.code=='0'){
		        		layer.msg("操作成功", {icon: 1});
		        		try{
		        		 var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		        		 if(index==null||typeof(index)=='undefined'){
		        			 var iframeId=parent.document.getElementsByTagName("iframe")[1].id;
		        			 index=iframeId.substring(iframeId.length-1);
		        		 }
		                  parent.layer.close(index); //再执行关闭
		                  parent.document.getElementsByTagName("iframe")[0].contentWindow.location.reload(true);
		        		}catch(e){
		        		}
		    		} else {
		    			if(data.code=='400'){
		    				layer.msg("操作失败:"+data.data.fsn, {icon: 0});
		    			}else{
		    				layer.msg("操作失败", {icon: 0});
		    			}
		    			
		    		}
		        }
		    });
		});
	
		form.verify({
			nlength:function(value){
				var i,sum;
				sum=0;
				for (i= 0; i < value.length; i++) {
					if((value.charCodeAt(i)>=0)&&(value.charCodeAt(i)<=255))
						sum=sum+1;
					else 
						sum=sum+2;
				}
				if(sum>200){
					return "只能输入200个字符或100个中文汉字!";
				}
			}
		});
		  function openGneDiv(width, height, url, title) {
		        $(window).one("resize", function () {
		            var index2 = layui.layer.open({
		                type: 2,
		                title: title,
		                skin: 'layui-layer-molv',
		                offset: 't',
		                area: [width, height],
		                content: url
		            })
		        }).resize();
		        layer.close(0);
		    }
	})
